package cn.hls.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * @fileName: User.java
 * @descrption: 模块实体类
 * @author : yinghui.zhang
 * @Email: uuhui@163.com
 * @date 2015-4-3
 * @version 1.0
 */
@Table(name = "T_MODULE")
@Entity
@DynamicInsert
@DynamicUpdate
public class Module extends BaseEntity {
	private static final long serialVersionUID = 4880479323879444416L;
	// 模块代码
	private String code;
	// 模块名称
	private String name;
	// 模块url地址
	private String url;
	// 模块序号 在菜单栏下显示根据sort来排序
	private int sort;
	// 上级模块
	private Module parent;
	// 是否展开 默认为不展开
	private Boolean expend = Boolean.valueOf(false);
	// 备注说明
	private String remark;
	// acl状态
	private int aclState;

	public Module() {

	}

	public Module(Long id, String name, String url, Boolean expend, Long pid, int aclState) {
		setId(id);
		this.name = name;
		this.url = url;
		this.expend = expend;
		this.pid = pid;
		this.aclState = aclState;
	}

	@Column(name = "code", length = 32, nullable = false)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "name", length = 32, nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "url", length = 256)
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "sort" )
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	// 父级编号
	private Long pid;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@NotFound(action = NotFoundAction.IGNORE)
	@JoinColumn(name = "P_ID")
	public Module getParent() {
		return parent;
	}

	public void setParent(Module parent) {
		this.parent = parent;
	}

	@Column(name = "remark", nullable = true, length = 100)
	public String getRemark() {
		return remark;
	}

	@Column(name = "is_expend", length = 1, columnDefinition = "CHAR default 0")
	public Boolean getExpend() {
		return expend;
	}

	public void setExpend(Boolean expend) {
		this.expend = expend;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Transient
	public int getAclState() {
		return aclState;
	}

	public void setAclState(int aclState) {
		this.aclState = aclState;
	}

	@Transient
	public Long getPid() {
		return pid;
	}

	public void setPid(Long pid) {
		this.pid = pid;
	}
}
